﻿/**
 * Label
 *
 * @author		Duarte Peixinho
 * @version		1.0
 */

package com.duartepeixinho.experimentLabel
{
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.events.Event;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.text.TextFieldAutoSize;
	
	public class Label extends Sprite
	{
		
		private var _experimentName:String;
		private var _link:String;
		private var _stageDefault:Stage;
		private var _text:TextField = new TextField();
		private var _text2:TextField = new TextField();
		private var _fontColor:uint = 0;
		private var _fontSize:uint = 0;
		private var _fontType:String;
		private var _backgroundColor:uint = 0;
		private var _outLineColor:uint = 0;
		
		/**
		 * Label Constructor
		 * @param	stage				Stage		Stage where is going to be applied
		 * @param	experimentName		String		Experiment Name
		 * @param	link				String		Experiment Link/html
		 * @param	outLineColor		uint		OutLine Color
		 * @param	backgroundColor		uint		Background Color
		 * @param	fontColor			uint		Font Color
		 * @param	fontSize			uint 		Font Size
		 * @param	fontType			tring		Font Type
		 */
		public function Label(stage:Stage,experimentName:String,link:String,outLineColor:uint=0xFFFFCC,backgroundColor:uint=0xFFFFCC,fontColor:uint=0x000000,fontSize:uint=12, fontType:String="verdana"):void 
		{
			_experimentName = experimentName;
			_link = link;
			_stageDefault = stage;
			_backgroundColor = backgroundColor;
			_fontColor = fontColor;
			_fontSize = fontSize;
			_outLineColor = outLineColor;
			_fontType = fontType;
			
			addChild(_text2);
			addChild(_text);
			
			initLabel();
		}
		/**
		 * Resize
		 * 
		 * @param	stage		Stage		Stage Changed
		 */
		public function resize(stage:Stage):void {
			_stageDefault = stage;
			initLabel();
		}
		
		/**
		 * Draw Label
		 */
		private function initLabel():void {
			graphics.clear();
			
			graphics.lineStyle(1,_outLineColor);
			graphics.beginFill(_backgroundColor, 1.0);
			graphics.drawRect(0, 0, _stageDefault.stageWidth, 20);
			graphics.endFill();
			var style:TextFormat = new TextFormat();
			style.font = _fontType;
			style.size = _fontSize;
			style.color = _fontColor;
			_text.x = 0;
			_text.y = 0;
			_text.autoSize = TextFieldAutoSize.LEFT;
			_text.defaultTextFormat = style;
			_text.selectable = false;
			_text.text = _experimentName;	
			
			_text2.y = 0;
			_text2.autoSize = TextFieldAutoSize.LEFT;
			_text2.defaultTextFormat = style;
			_text2.selectable = false;	
			_text2.htmlText = _link;
			_text2.x = _stageDefault.stageWidth - _text2.width;
			
		}
	}
}